package com.example.tool.activtiy;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.tool.R;
import com.example.tool.activtiy.base.BaseActivity;
import com.example.tool.adapter.DbAdapter;
import com.example.tool.adapter.base.decoration.RecycleViewDivider;
import com.example.tool.mvp.CommonPresent;
import com.example.tool.widget.PopUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

/**
 * Created Date 2019/9/27
 *
 * @author liangkun
 * description：数据库界面
 */
public class DbTestActivity extends BaseActivity<CommonPresent> {
    @BindView(R.id.tv_title)
    protected TextView tvTitle;
    @BindView(R.id.ll_container)
    protected LinearLayout llContainer;
    @BindView(R.id.rv_public)
    protected RecyclerView recyclerView;
    LinearLayoutManager linearLayoutManager;
    private String[] list = {"增加", "删除", "查询", "模糊查询", "区间查询70年-89年之间", "25岁区间查询", "大于30岁查询"
            , "限制刷新查询"};
    private DbAdapter dbAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_public;
    }

    @Override
    protected void initView() {
        tvTitle.setText("GreenDao增删查改");
        linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
        recyclerView.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL,
                getResources().getDimensionPixelOffset(R.dimen.sw_dp_15), 0, 0,
                getResources().getColor(R.color.color_white)));
        recyclerView.setLayoutManager(linearLayoutManager);
        dbAdapter = new DbAdapter(this, getData());
        recyclerView.setAdapter(dbAdapter);
    }

    private List<String> getData() {
        return new ArrayList<>(Arrays.asList(list));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

        dbAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (position) {
                    case 0:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "增加");
//                        PopUtil.getInstance().showBottomLagerPop(DbTestActivity.this, llContainer, "");
                        break;
                    case 1:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "删除");
                        break;
                    case 2:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "查询");
                        break;
                    case 3:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "模糊查询");
                        break;
                    case 4:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "年份区间查询");
                        break;
                    case 5:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "25岁区间查询");
                        break;
                    case 6:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, ">30岁查询");
                        break;
                    case 7:
                        PopUtil.getInstance().showBottomDbPop(DbTestActivity.this, llContainer, "限制刷新查询");
                        break;
                }
            }
        });

    }

    @Override
    protected CommonPresent createPresenter() {
        return null;
    }
}
